<template>
  <div class="mb80">
    <div class="top">
      <div class="add-inp">
        <strong v-on:click="gett">{{currentCity}}</strong><span id="currentCity"></span>
        <img src="images/address.png"/>
        <div class="add-inp_input fr"><img src='images/search.png' class="search"/>搜索</div>
      </div>
      <div class="clearFloat select">
        <ul class="clearFloat">
          <li class="checked">发布时间</li>
          <li>截止时间</li>
          <li>距离</li>
          <li>赏金</li>
        </ul>
      </div>
    </div>
    <!--列表部分-->
    <div class="list clearFloat mt5" v-for="value in response_data_list">
      <a href="detail.html">
        <div>
          <ul class="clearFloat">
            <li class="userImg"><img v-bind:src="value.update_user_headimgurl" draggable=false/></li>
            <li class="til">{{value.title}}</li>
            <li class="pay fr">10元</li>
          </ul>
        </div>
        <div class="hrc">
          <div class="hr fr"></div>
        </div>
        <div>
          <ul class="clearFloat userinf">
            <li class="nickName">{{value.update_user_nickname}}</li>
            <li class="time">{{value.lastdate}}</li>
            <li class="address fr">{{value.address}}</li>
          </ul>
        </div>
      </a>
    </div>
  </div>
</template>

<script>
  import Vue from 'vue'
  import Helect from '../common/Helect'
  import bmap from '../../libs/bmap-wx/bmap-wx.min.js'
  import VueResource from 'vue-resource'
  Vue.use(VueResource);
  var wxMarkerData = [];  //定位成功回调对象
  export default {
    components: {
      Helect
    },
    ready: function () {
      var that = this
      that.$http({
        method: 'post',
        headers: {"X-Requested-With": "XMLHttpRequest"},
        emulateJSON: true,
        url: '',
        data: {}
      }).then(function (data) {
        that.contents = data.data.res
      }, function (error) {

      })
    },
    data () {
      return {
        ak: '752vkaTfiOQVEGgEd4SqYkbiAGxhGxwf',
        currentCity: '深圳',
        category: '带饭',
        response_data_list: [],
      }
    },
    //获取当前城市
    methods: {
      gett: function () {
        const s = document.createElement('script');
        s.type = 'text/javascript';
        s.src = 'http://api.map.baidu.com/api?v=2.0&ak=uXPwxYUexC96m3YGSSpNSzp599WCRSCO';
        document.body.appendChild(s);
        var that = this;
        var map = new BMap.Map("currentCity");

        function myFun(result) {
          var cityName = result.name.slice(0, 2);
          map.setCenter(cityName);
          that.currentCity = cityName
        }

        var myCity = new BMap.LocalCity();
        myCity.get(myFun);
      }
    },
    ready: function () {
      Vue.use(VueResource);
      var that = this
       var data = {
              "category": that.category,
              "page":1,
              "num":10,
            }
            console.log("+++++++")
            console.log(data)

            //获取任务列表
            this.$http.post('http://xyg.bigdatas.top/get_list', data, {"emulateJSON": false}).then(function (data) {
              if(data.data.code ==0){
                that.response_data_list = data.data.data
              }else{}
                    })
      //获取js_sdk权限
      this.$http.post('http://xyg.bigdatas.top/get_jssdk_config', {"url": window.location.href}, {"emulateJSON": true}).then(function (data) {
        wx.config({
          debug: false,
          appId: 'wx7491574828fade87',
          timestamp: data.data.data.timestamp,
          nonceStr: data.data.data.nonceStr,
          signature: data.data.data.signature,
          jsApiList: [
            'getLocation',
          ]
        });
        wx.ready(function () {
          wx.getLocation({
            type: 'wgs84', // 默认为wgs84的gps坐标，如果要返回直接给openLocation用的火星坐标，可传入'gcj02'
            success: function (res) {
              var latitude = res.latitude; // 纬度，浮点数，范围为90 ~ -90
              var longitude = res.longitude; // 经度，浮点数，范围为180 ~ -180。
              var speed = res.speed; // 速度，以米/每秒计
              var accuracy = res.accuracy; // 位置精度
              that.$http.post('http://xyg.bigdatas.top/get_address', {
                "Latitude": latitude,
                "Longitude": longitude,
              }, {"emulateJSON": false}).then(function (data) {
                that.currentCity = data.data.result.addressComponent.city.slice(0, 2)
              })
            }
          });
        });

      })
    }
  }
</script>

<style scoped>
  a {
    color: #333;
  }

  .fl {
    float: left;
  }

  .mt5 {
    margin-top: 5px;
  }

  .fr {
    float: right;
  }

  .mt10 {
    margin-top: 10px;
  }

  ul {
    padding: 0;
    margin: 0 auto;
  }

  ul li {
    float: left;
    list-style-type: none;
    margin: 0;
    padding: 0 12px;
    text-align: center;
  }

  .select li {
    padding: 0 16px
  }

  .clearFloat:after {
    content: '';
    display: block;
    clear: both;
    hisibility: hidden;
  }

  body {
    background-color: #EFEFF4;
  }

  .top {
  }

  .add-inp {
    height: 30px;
    line-height: 30px;
    padding: 10px 8px;
  }

  .add-inp img {
    width: 15px;
    height: 15px;
    vertical-align: middle;
  }

  .search {
    width: 16px !important;
    height: 16px !important;
    vertical-align: middle;
    margin-right: 4px;
  }

  .add-inp_input {
    min-width: 81%;
    height: 25px;
    line-height: 25px;
    border: 0;
    text-align: center;
    background-color: #fff;
    color: #888888;
    margin: 2px 0;
    margin-right: 5px;
    font-size: 15px;
    border-radius: 5px;
  }

  .select {
    background-color: #fff;
    padding: 10px 0;
    color: #4a4a4a;
    font-size: 14px;
  }

  .select li {
    width: 25%;
    padding: 0;
  }

  .select li:hover {
    color: #1aad19;
  }

  .checked {
    color: #1aad19;
  }

  .list {
    background-color: #fff;
    padding: 8px 10px;
  }

  .userImg {
    width: 15%;
    height: 40px;
    padding: 0;
  }

  .userImg img {
    border-radius: 50%;
    width: 40px;
    height: 40px;
  }

  .nickName {
    width: 15%;
    height: 30px;
    line-height: 40px;
    padding: 0;
	white-space:nowrap; overflow:hidden; text-overflow:ellipsis
  }

  .time, .address {
    height: 30px;
    line-height: 40px;
  }

  .time {
    width: 30%;
    padding: 0
  }

  .address {
    width: 55%;
    padding: 0;
    text-align: right;
	white-space:nowrap; overflow:hidden; text-overflow:ellipsis
  }

  .userinf {
    font-size: 12px;
    color: #888888;
  }

  .til, .pay {
    width: 70%;
    line-height: 40px;
    font-weight: bold;
    font-size: 16px;
    padding: 0;
  }

  .til {
    text-align: left;
  }

  .pay {
    width: 15%;
    font-size: 18px;
    color: #d0011b;
  }

  .hr {
    width: 85%;
    border-top: 1px solid #d0d0d0;
  }

  .hrc {
    width: 100%;
    margin: 0 auto;
  }

  .currentCity {
    visibility: hidden;
  }
  .mb80{margin-bottom:60px;}
</style>
